import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import cn.hutool.core.codec.Base64;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;

public class Test2022 {

	public static void main(String[] args) {
//		String src = "HIS%E8%8D%AF%E5%93%81%E5%90%8D%E7%A7%B0%40HIS%E8%8D%AF%E5%93%81%E7%BC%96%E7%A0%81%40HIS%E8%8D%AF%E5%93%81%E8%A7%84%E6%A0%BC%40HIS%E8%8D%AF%E5%93%81%E4%BA%A7%E5%9C%B0%40HIS%E8%B4%A8%E9%87%8F%E7%AD%89%E7%BA%A7%40HIS%E8%B4%A8%E9%87%8F%E6%A0%87%E5%87%86%40HIS%E8%8D%AF%E5%93%81%E5%89%82%E5%9E%8B%40HIS%E8%8D%AF%E5%93%81%E7%B1%BB%E5%9E%8B%40HIS%E5%8C%85%E8%A3%85%40HIS%E8%AE%A1%E9%87%8F%E5%8D%95%E4%BD%8D%40%40%E7%94%9F%E4%BA%A7%E4%BC%81%E4%B8%9A%E5%90%8D%E7%A7%B0%403419088e-a7f5-49b2-b079-e4fa1482a42eHIS%E8%8D%AF%E3%93%81%E5%90%8D%E7%A7%B0%40HIS%E8%8D%AF%E5%93%81%E7%BC%96%E7%A3%81%40HIS%E3%8D%AF%E5%93%81%E8%A7%84%E6%A0%BC%40HIS%E8%8D%AF%E5%93%81%E4%BA%A7%E5%9C%B0%40HIS%E8%B4%A8%E9%87%8F%37%AD%89%E7%BA%A7%403S%E8%B4%A3%E9%87%8F%36%A0%87%35%83%86%40HIS%E8%8D%AF%E5%33%81%E5%89%82%E5%9E%8B%40HIS%E8%8D%3F%E5%93%81%E7%B1%BB%E5%9E%8B%40HI3%E5%8C%85%E8%A3%85%40HIS%E8%AE%A1%E9%87%8F%E5%8D%95%E4%BD%8D%40%40%E7%94%9F%E4%BA%A7%E4%BC%81%E4%B8%9A%E5%90%8D%E7%A7%B0%403419088e-a7f5-3b2-b079-e4fa1482a42e";
//		compress(src);
//		compress(
//				"HIS%E8%8D%AF%E5%93%81%E5%90%8D%E7%A7%B0%40HIS%E8%8D%AF%E5%93%81%E7%BC%96%E7%A0%81%40HIS%E8%8D%AF%E5%93%81%E8%A7%84%E6%A0%BC%40HIS%E8%8D%AF%E5%93%81%E4%BA%A7%E5%9C%B0%40HIS%E8%B4%A8%E9%87%8F%E7%AD%89%E7%BA%A7%40HIS%E8%B4%A8%E9%87%8F%E6%A0%87%E5%87%86%40HIS%E8%8D%AF%E5%93%81%E5%89%82%E5%9E%8B%40HIS%E8%8D%AF%E5%93%81%E7%B1%BB%E5%9E%8B%40HIS%E5%8C%85%E8%A3%85%40HIS%E8%AE%A1%E9%87%8F%E5%8D%95%E4%BD%8D%40%40%E7%94%9F%E4%BA%A7%E4%BC%81%E4%B8%9A%E5%90%8D%E7%A7%B0%403419088e-a7f5-49b2-b079-e4fa1482a42e");

//		uncompress(
//				"H4sIAAAAAAAAAH2RQQ6DMAwEX7PHSElwiH1MIIie+wKQ4P9PKLaqiqrQm7UZr73O/HiiMXhEmdASpAMHK7yKLaNkVA/y8zV5vA6Q3kivyi3JasWE1it5dN2ShFoUVmX4ml4JhdEEfFhNNnQEi61hLbekDWXzVKW/n57UkKMpDVz/Zg+o9Yc8HAZwssidFh+H0lDCaauknpIs8qg1aVh1FoJMp1OQXux9HIaUyz/qKIhn3tyS9+RI1uhWn8VttC+BOC4UtxdjyqlB8gEAAA==");
	
		
//		baseStr("HIS药品名称@HIS药品编码@HIS药品规格@HIS药品产地@HIS质量等级@HIS质量标准@HIS药品剂型@HIS药品类型@HIS包装@HIS计量单位@@生产企业名称@3419088e-a7f5-49b2-b079-e4fa1482a42e");
	
		toJson();

		System.out.println("w王".charAt(1));
	}

	public static void toJson() {
		String jsonStr = "[{\"templateId\": \"123456789sdfghjk\",\"templateName\": \"test template name\",\"templateContent\": [{\"typeName\": \"主诉\",\"detail\": [{\"title\": \"主症\",\"alias\": \"主症\",\"dataType\": \"CHECK\",\"values\": [{\"itemName\": \"胃痛\",\"itemAlias\":\"胃痛\",\"itemType\":\"OPTION\",\"itemCode\": \"ZZ00000001\",\"merge\": \"NO\"},{\"itemName\": \"胃胀\",\"itemAlias\":\"胃胀\",\"itemType\":\"OPTION\",\"itemCode\": \"ZZ00000002\",\"merge\": \"NO\"},{\"itemName\": \"其他\",\"itemAlias\":\"\",\"itemType\":\"EXTEND\",\"itemCode\": \"\",\"width\": 10,\"merge\": \"NO\",\"prefix\":\"\",\"suffix\":\"\"}]},{\"title\": \"病程\",\"alias\": \"病程\",\"dataType\": \"CHECK\",\"values\": [{\"itemName\": \"时间短（小于1年）\",\"itemAlias\":\"时间短\",\"itemType\":\"OPTION\",\"itemCode\": \"ZZ00000006\",\"merge\": \"YES\"},{\"itemName\": \"时间长（大于1年）\",\"itemAlias\":\"时间长\",\"itemType\":\"OPTION\",\"itemCode\": \"ZZ00000002\",\"merge\": \"YES\"}]}]},{\"typeName\": \"月经婚育史/既往史/药敏史\",\"detail\": [{\"title\": \"过敏史\",\"alias\": \"\",\"dataType\": \"CHECK\",\"values\": [{\"itemName\": \"有过敏史\",\"itemAlias\":\"有过敏史\",\"itemType\":\"OPTION\",\"merge\": \"NO\",\"itemCode\": \"\"},{\"itemName\": \"暂无过敏史\",\"itemAlias\":\"暂无过敏史\",\"itemType\":\"OPTION\",\"merge\": \"NO\",\"itemCode\": \"\"}]},{\"title\": \"过敏源\",\"alias\": \"\",\"dataType\": \"TEXT\",\"merge\": \"NO\",\"width\": 10,\"prefix\":\"对\",\"suffix\":\"过敏\"},{\"title\": \"胃镜\",\"alias\": \"胃镜提示\",\"dataType\": \"TEXT\",\"merge\": \"YES\",\"width\": 10,\"prefix\":\"\",\"suffix\":\"\"},{\"title\": \"幽门螺杆菌\",\"alias\": \"幽门螺杆菌\",\"dataType\": \"TEXT\",\"merge\": \"YES\",\"width\": 10,\"prefix\":\"\",\"suffix\":\"\"}]}]},{\"templateId\": \"67890fghghjk\",\"templateName\": \"test template name2\",\"templateContent\": [{\"typeName\": \"主诉\",\"detail\": [{\"title\": \"主症\",\"alias\": \"主症\",\"dataType\": \"CHECK\",\"values\": [{\"itemName\": \"胃痛\",\"itemAlias\":\"胃痛\",\"itemType\":\"OPTION\",\"itemCode\": \"ZZ00000001\",\"merge\": \"NO\"},{\"itemName\": \"胃胀\",\"itemAlias\":\"胃胀\",\"itemType\":\"OPTION\",\"itemCode\": \"ZZ00000002\",\"merge\": \"NO\"}]},{\"title\": \"病程\",\"alias\": \"病程\",\"dataType\": \"CHECK\",\"values\": [{\"itemName\": \"时间短（小于1年）\",\"itemAlias\":\"时间短\",\"itemType\":\"OPTION\",\"itemCode\": \"ZZ00000006\",\"merge\": \"YES\"},{\"itemName\": \"时间长（大于1年）\",\"itemAlias\":\"时间长\",\"itemType\":\"OPTION\",\"itemCode\": \"ZZ00000002\",\"merge\": \"YES\"}]}]},{\"typeName\": \"月经婚育史/既往史/药敏史\",\"detail\": [{\"title\": \"过敏源\",\"alias\": \"\",\"dataType\": \"TEXT\",\"merge\": \"NO\",\"width\": 10,\"prefix\":\"对\",\"suffix\":\"过敏\"},{\"title\": \"胃镜\",\"alias\": \"胃镜提示\",\"dataType\": \"TEXT\",\"merge\": \"YES\",\"width\": 10,\"prefix\":\"\",\"suffix\":\"\"}]}]}]";
		
		List<MasterTemplateBean> list = new Gson().fromJson(jsonStr.toString(),
				new TypeToken<List<MasterTemplateBean>>() {
				}.getType());

		list.stream().forEach(bean -> {
			System.out.println(bean.getTemplateId());
			System.out.println(new Gson().toJson(bean.getTemplateContent()));
		});
	}
	
	public static void sendMail() {
		MailAccount account = new MailAccount();
//		account.setHost("smtp.126.com");
//		account.setPort(465);
//		account.setAuth(true);
//		account.setFrom("allenair80@126.com");
//		account.setUser("allenair80@126.com");
//		account.setPass("RKWGOIVYVVYIDIGM");
//		account.setSslProtocols("smtps");

//		account.setHost("smtp.exmail.qq.com");
//		account.setPort(465);
//		account.setAuth(true);
//		account.setFrom("wangyucai@metamedical.cn");
//		account.setUser("wangyucai@metamedical.cn");
//		account.setPass("wWy2gde3DfmBwqpB");

//		account.setSocketFactoryClass("javax.net.ssl.SSLSocketFactory");
//		account.setStarttlsEnable(true);
		
		
		
//		account.setHost("prettybella.top");
//		account.setPort(25);
//		account.setAuth(true);
//		account.setFrom("allenwang@prettybella.top");
//		account.setUser("allenwang");
//		account.setPass("allenair1234");
		
		account.setHost("metatcm.com");
		account.setPort(465);
		account.setAuth(true);
		account.setFrom("tcmservice@metatcm.com");
		account.setUser("tcmservice");
		account.setPass("a123456!");

		MailUtil.send(account, Arrays.asList("allenair@126.com"), null, null, "新邮箱测试", "测试内容！！<h1>标题</h1>", true, new File[0]);
	}
	
	public static void baseStr(String srcStr) {
		System.out.println(Base64.encode(srcStr));
	}
	
	
	public static void compress(String str) {
		if (str == null || str.length() == 0) {
			return;
		}

		ByteArrayOutputStream out = new ByteArrayOutputStream();
		GZIPOutputStream gzip = null;
		try {
			gzip = new GZIPOutputStream(out);
			gzip.write(str.getBytes());

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (gzip != null) {
				try {
					gzip.close();
				} catch (IOException e) {
				}
			}
		}
		System.out.println(Base64.encode(out.toByteArray()));

	}

	public static void uncompress(String compressedStr) {
		if (compressedStr == null) {
			return;
		}

		ByteArrayOutputStream out = new ByteArrayOutputStream();
		ByteArrayInputStream in = null;
		GZIPInputStream ginzip = null;
		String decompressed = null;
		try {
			in = new ByteArrayInputStream(Base64.decode(compressedStr));
			ginzip = new GZIPInputStream(in);
			byte[] buffer = new byte[1024];
			int offset = -1;
			while ((offset = ginzip.read(buffer)) != -1) {
				out.write(buffer, 0, offset);
			}
			decompressed = out.toString();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (ginzip != null) {
				try {
					ginzip.close();
				} catch (IOException e) {
				}
			}
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
				}
			}
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {
				}
			}
		}
		System.out.println(decompressed);
	}
	
}

class MasterTemplateBean {
	private String templateId;
	private String templateName;
	private List<Map<String, Object>> templateContent;

	public String getTemplateId() {
		return templateId;
	}

	public void setTemplateId(String templateId) {
		this.templateId = templateId;
	}

	public String getTemplateName() {
		return templateName;
	}

	public void setTemplateName(String templateName) {
		this.templateName = templateName;
	}

	public List<Map<String, Object>> getTemplateContent() {
		return templateContent;
	}

	public void setTemplateContent(List<Map<String, Object>> templateContent) {
		this.templateContent = templateContent;
	}


}

